// index.js
// 获取应用实例
const app = getApp()
import {
  goodsList
} from '../../utils/api'

Page({
  data: {
    keyword: '',
    stores: [],
    storeId: '',
    name: '',
    goods: [],
  },
  onLoad(options) {
    const {
      name,
      storeId
    } = options
    this.setData({
      name,
      storeId
    })
    this.getList()
  },
  getList() {
    goodsList(this.data.storeId).then(res => {
      res.map(item => {
        if (item.subtitle && item.subtitle.includes(',')) {
          item.subtitle = item.subtitle.split(',')
        }
      })
      this.setData({
        goods: res
      })
    })
  },
  bindconfirm(e) {
    this.setData({
      keyword: e.detail.value
    })
    this.getList()
  },
  // 事件处理函数
  toDetail(e) {
    wx.navigateTo({
      url: '/pages/goodsDetail/index?storeId=' + this.data.storeId +  '&id=' + e.currentTarget.dataset.id,
    })
  },
  toUse() {
    wx.navigateTo({
      url: '/pages/useimmed/useimmed?storeId=' + this.data.storeId,
    })
  },
  toRecruit() {
    wx.navigateTo({
      url: '/pages/rucruit/rucruit',
    })
  },
  toHealthy () {
    wx.navigateTo({
      url: '/pages/healthcard/healthcard?storeId=' + this.data.storeId,
    })
  },
})